from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from djiape.sales.models import Client, TransactionType, PaymentType
from djiape.entities.models import Currency

class Journal(models.Model):
    client = models.ForeignKey(Client, verbose_name=_('client'))
    ar_operation = models.ForeignKey(TransactionType, verbose_name=_('transaction'), related_name='ar_operation')
    folio = models.CharField(_('folio'), max_length=10)
    date = models.DateTimeField(_('date'), auto_now_add=True)
    ar_aux_oper = models.ForeignKey(TransactionType, verbose_name=_('transaction'), blank=True, null=True, related_name='ar_aux_oper')
    aux_fol = models.CharField(_('reference'), max_length=10, blank=True, null=True)
    credit_term = models.IntegerField(_('credit terms'), default=0)
    currency = models.ForeignKey(Currency, verbose_name=_('currency'))
    rate = models.DecimalField(_('rate'), max_digits=14, decimal_places=2, default=1)
    total = models.DecimalField(_('total'), max_digits=14, decimal_places=2)
    tax = models.DecimalField(_('tax'), max_digits=14, decimal_places=2)
    credit = models.DecimalField(_('credit'),max_digits=14, decimal_places=2, blank=True, null=True, editable=False)
    debit = models.DecimalField(_('debit'),max_digits=14, decimal_places=2, blank=True, null=True, editable=False)
    gl_operation = models.IntegerField(_('gl operation'), default=0)
    sl_operation = models.IntegerField(_('sl operation'), default=0)
    status = models.CharField(_('status'), max_length=1, default='N')
    user = models.ForeignKey(User, verbose_name=_('user'))

class Payment(models.Model):
    client = models.ForeignKey(Client, verbose_name=_('client'))
    pay_operation = models.ForeignKey(TransactionType, verbose_name=_('transaction'), related_name='pay_operation')
    folio = models.CharField(_('folio'), max_length=10)
    date = models.DateTimeField(_('date'), auto_now_add=True)
    type = models.ForeignKey(PaymentType, verbose_name=_('payment type'), blank=True, null=True)
    currency = models.ForeignKey(Currency, verbose_name=_('currency'))
    rate = models.DecimalField(_('rate'), max_digits=14, decimal_places=2, default=1)
    total = models.DecimalField(_('total'), max_digits=14, decimal_places=2)
    tax = models.DecimalField(_('tax'), max_digits=14, decimal_places=2)
    status = models.CharField(_('status'), max_length=1, default='N')
    user = models.ForeignKey(User, verbose_name=_('user'))
